#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;
class Solution {
public:
    bool checkInclusion(string s1, string s2) {
        unordered_map<char,int>need,windows;
        for(char c:s1)need[c]++;
        int r=0,l=0,valid=0;
        while(r<s2.size())
        {
            char a=s2[r];
            r++;
            if(need.count(a))
            {
                windows[a]++;
                if(windows[a]==need[a])valid++;
            }
            while(r-l>=s1.size())
            {
                if(valid==need.size())return true;
                char c=s2[l];
                l--;
                if(need.count(c))
                {
                    if(windows[c]==need[c])valid--;
                    windows[c]--;
                }
            }
        }
        return false;


    }
};